package com.besall.allbase.view.activity.chipstoollevel4.protocol.FitnessParams;

import android.content.Context;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.Button;
import android.widget.LinearLayout;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.DialogFragment;

import  bb.lanxing.R;

public class HRLiveControl extends DialogFragment implements View.OnClickListener {
    public String[] modes = {"Start", "Stop"};
    private LinearLayout mView;
    private Context mContext;
    private ConfigCallBack mConfigCallback;
    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        getDialog().requestWindowFeature(Window.FEATURE_NO_TITLE);
        mContext = inflater.getContext();
        View view = inflater.inflate(R.layout.config_devicemode, container, false);
        initView(view);
        return view;
    }

    public void initView(View view){
        mView = view.findViewById(R.id.modelist);
        DisplayMetrics screen = new DisplayMetrics();
        getActivity().getWindowManager().getDefaultDisplay().getMetrics(screen);
        int width = screen.widthPixels;

        for (int i = 0; i < modes.length; i++) {
            View viewE = new View(mContext);
            viewE.setId(i);
            viewE.setLayoutParams(new ViewGroup.LayoutParams((int) (width * 0.45), 10));

            Button button = new Button(mContext);
            button.setText("    " + modes[i]);
            button.setId(i);
            button.setOnClickListener(this);
            button.setTextSize(10);
            button.setTextAlignment(View.TEXT_ALIGNMENT_CENTER);
            button.setGravity(Gravity.CENTER_VERTICAL);
            button.setBackgroundResource(R.drawable.rectangle_cardbtn_reflect);

            mView.addView(button);
            mView.addView(viewE);
        }

    }

    public void setConfigCallback(ConfigCallBack configCallback) {
        mConfigCallback = configCallback;
    }


    @Override
    public void onClick(View v) {
        dismissAllowingStateLoss();
        if (mConfigCallback != null){
            mConfigCallback.modeClick(v.getId());
        }
    }


    public interface ConfigCallBack {

        void modeClick(int id);
    }



}
